/*
* pps_bom
*/
package com.pitop.project.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.ProjectStaffException;
import com.pitop.project.api.ProjectStaffFeignApi;
import com.pitop.project.entity.ProjectStaff;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 参与项目的员工
 *
 * @author berton
 */
@Service("projectStaffSVImpl")
@Slf4j
public class ProjectStaffSVImpl {

    @Autowired
    private ProjectStaffFeignApi projectStaffFeignApi;

    /**
     * 加载一个对象ProjectStaff
     *
     * @param id * @param projectCode 项目编码* @param accountCode 员工编码
     * @return ProjectStaff
     */
    public ProjectStaff load(Long id, String projectCode, String accountCode) {
        if (id == null && projectCode == null && accountCode == null) {
            throw new ProjectStaffException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectStaffFeignApi.load(id, projectCode, accountCode);
    }

    /**
     * 加载一个对象ProjectStaff 通过id,(将查询关联数据)
     *
     * @param id
     * @return ProjectStaff
     */
    public ProjectStaff loadById(Long id) {
        if (id == null) {
            throw new ProjectStaffException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectStaffFeignApi.loadById(id);
    }

    /**
     * 加载一个对象ProjectStaff 通过projectCode,(将查询关联数据)
     *
     * @param projectCode 项目编码
     * @return ProjectStaff
     */
    public ProjectStaff loadByProjectCode(String projectCode) {
        if (projectCode == null) {
            throw new ProjectStaffException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectStaffFeignApi.loadByProjectCode(projectCode);
    }

    /**
     * 加载一个对象ProjectStaff 通过accountCode,(将查询关联数据)
     *
     * @param accountCode 员工编码
     * @return ProjectStaff
     */
    public ProjectStaff loadByAccountCode(String accountCode) {
        if (accountCode == null) {
            throw new ProjectStaffException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return projectStaffFeignApi.loadByAccountCode(accountCode);
    }


    /**
     * 删除对象ProjectStaff
     *
     * @param id * @param projectCode 项目编码* @param accountCode 员工编码
     */

    public void delete(Long id, String projectCode, String accountCode) {
        if (id == null && projectCode == null && accountCode == null) {
            throw new ProjectStaffException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        projectStaffFeignApi.delete(id, projectCode, accountCode);
    }

    /**
     * 查询ProjectStaff分页
     *
     * @param projectStaff 对象
     * @param curPage      当前页
     * @param pageSize     分页条数
     * @return List<ProjectStaff>
     */
    public List<ProjectStaff> list(ProjectStaff projectStaff, int curPage, int pageSize) {
        return projectStaffFeignApi.list(projectStaff, curPage, pageSize);
    }

    /**
     * 查询ProjectStaff分页
     *
     * @param id       * @param projectCode  项目编码* @param accountCode  员工编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<ProjectStaff>
     */
    public List<ProjectStaff> list(Long id, String projectCode, String accountCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        ProjectStaff projectStaff = new ProjectStaff();
        projectStaff.setId(id);
        projectStaff.setProjectCode(projectCode);
        projectStaff.setAccountCode(accountCode);

        return projectStaffFeignApi.list(projectStaff, curPage, pageSize);
    }

    public int count(Long id, String projectCode, String accountCode) {
        return projectStaffFeignApi.count(id, projectCode, accountCode);
    }

    public int count(ProjectStaff projectStaff) {
        return projectStaffFeignApi.count(projectStaff);
    }

    /**
     * 保存
     *
     * @param projectStaff 实体
     * @throws BaseException
     */
    public void save(ProjectStaff projectStaff) {
        if (projectStaff == null) {
            throw new ProjectStaffException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        projectStaffFeignApi.build(projectStaff);
    }

    /**
     * 更新
     *
     * @param projectStaff 实体
     * @throws BaseException
     */
    public void modify(ProjectStaff projectStaff) {
        if (projectStaff == null) {
            throw new ProjectStaffException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        projectStaffFeignApi.modify(projectStaff);
    }
}
